package migranitodejava.introduccion;

import org.hibernate.Session;
import org.hibernate.Transaction;

public class Test {

	public static void main(String[] args) throws Exception {
		Test t = new Test();
		t.alta();
	}

	public void alta() throws Exception {
		Session sess = SessionManager.getSession();
		Transaction tx = null;
		try {
			tx = sess.beginTransaction();

			Auto a = new Auto();
			a.setMarca("marca");
			a.setModelo("modelo");
			sess.save(a);

			tx.commit();
		} catch (Exception e) {
			if (tx != null) {
				tx.rollback();
			}
			throw e;
		} finally {
			sess.close();
		}
	}
}
